package com.googlecode.mvchat.protocol;

import org.apache.commons.lang3.ArrayUtils;

public class Message {
	
	private String message;
	private long sender;
	private long reciever;
	
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public long getSender() {
		return sender;
	}
	public void setSender(long sender) {
		this.sender = sender;
	}
	public long getReciever() {
		return reciever;
	}
	public void setReciever(long reciever) {
		this.reciever = reciever;
	}
	
	public byte[] toBytes(){
		byte[] result = (sender+";"+reciever+";"+message+"\n").getBytes();
		return result;
	}

	
	public void populateFromByteArray(byte[] arr){
		String message = new String(arr);
		
		String[] splitMsg = message.split(";");
		if(splitMsg.length != 3)
			return;
		
		setSender(Long.parseLong(splitMsg[0]));
		setReciever(Long.parseLong(splitMsg[1]));
		setMessage(splitMsg[2]);
	}
}
